package Day_06;
/* 流程分析：                     方法：
*  1. 评委人数 N                  scanner  n
*  2. 评委打分                    double[] getScore(n)
*  3. 得到平均分（去掉最高、最低分） double avg(double[] Score)
*  4. 展示平均分                  System.out.println(""+String.format("%.2f",Score))
* */

import java.util.Scanner;
public class StandardTwoDemo {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入评委人数：");
        int num = scan.nextInt();
        double[] score = getScore(num);
        double average = avg(score);
        System.out.println("最终得分是："+String.format("%.2f",average));
    }

    // 评委打分
    public static double[] getScore(int n){
        double[] s = new double[n];
        Scanner scan = new Scanner(System.in);
        for (int i = 0; i < n; i++) {
            System.out.println("第"+(i+1)+"位评委的打分：");
            s[i] = scan.nextDouble();
        }
        return s;
    }
    // 得到平均分（去掉最高、最低分）
    public static double avg(double[] a){
        double max = a[0], min = a[0] ,avg = 0;
        for (int i = 0; i < a.length; i++) {
            if(max < a[i]){
                max = a[i];
            }
        }
        for (int i = 0; i < a.length; i++) {
            if(min > a[i]){
                min = a[i];
            }
        }

        for (int i = 0; i < a.length; i++) {
            avg += a[i];
        }
        avg = (avg - max - min) / (a.length - 2);
        return avg;
    }
}
